<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
  <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
</head>
<style>
    .layui-form-label {
	    width: 140px;
	}
</style>
<body style="padding:10px;">
  <div class="tplay-body-div">
    <div style="margin-top: 20px;">
    </div>
    <form class="layui-form" id="admin">
			{if $caipin !=null}
				<input type="hidden" name="id" value="{$caipin.id}"/>
			{/if}
      <div class="layui-form-item">
        <label class="layui-form-label">所属门店</label>
        <div class="layui-input-inline">
          <select name="store_id" id="store_id" lay-filter="aihao"  lay-verify="required" lay-search>
            <option value="">请选择门店</option>
            {volist name="stores" id="vo"}
                  <option value="{$vo.id}">{$vo.store_name}</option>
            {/volist}
          </select>
        </div>
      </div>
      
      <div class="layui-form-item">
        <label class="layui-form-label">所属分类</label>
        <div class="layui-input-inline">
          <select name="type_id" id="type_id" lay-filter="aihao"  lay-verify="required" lay-search>
            <option value="">请选择分类</option>
            {volist name="list" id="vo"}
                  <option value="{$vo.id}" >{$vo.name}</option>
            {/volist}
          </select>
        </div>
      </div>
      
      <div class="layui-form-item">
        <label class="layui-form-label">菜品名称</label>
        <div class="layui-input-inline">
          <input {if $caipin !=null} value="{$caipin.name}" {/if} name="name" lay-verify="required" autocomplete="off" placeholder="请输入菜品名称" class="layui-input" type="text">
        </div>
      </div>
       <div class="layui-form-item">
        <label class="layui-form-label">售价</label>
        <div class="layui-input-inline">
          <input {if $caipin !=null} value="{$caipin.price}" {/if} name="price"  lay-verify="required" autocomplete="off" placeholder="请输入售价" class="layui-input" type="text"> ￥/份
        </div>
      </div>
            <div class="layui-form-item">
        <label class="layui-form-label">菜品库存</label>
        <div class="layui-input-inline">
          <input {if $caipin !=null} value="{$caipin.store}" {/if} name="store" lay-verify="required" autocomplete="off" value="0" class="layui-input" type="text">
        </div>
      </div>
      
       
      
      
      <div class="layui-upload" id="upload-thumb">
        <label class="layui-form-label">图片</label>
        <button type="button" class="layui-btn" id="thumb">上传图片</button>
        <div class="layui-upload-list">
          <label class="layui-form-label"></label>
          <img class="layui-upload-img" {if $caipin !=null} src="{$caipin.thumb}" {/if} id="demo1" width="150" height="150" >
          <p id="demoText"></p>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">选择标签</label>
        <div class="layui-input-inline">
        	{volist name="$bq" id="vo"}
								<input  value="{$vo.id}" type="radio" {if $caipin !=null&&$vo.id==$caipin.bq_id} checked="checked" {/if} name="bq_id" />{$vo.name}
					{/volist}
          
        </div>
      </div>
       <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-inline">
          <input {if $caipin !=null} value="{$caipin.sort}" {/if} name="sort"  lay-verify="required" autocomplete="off" value="0" class="layui-input" type="text">
        </div>
      </div>
      

      
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>
      
    </form>


    <script src="__PUBLIC__/layui/layui.js"></script>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>
    <script>
    	var caipin="{$caipin['id']}";
    	if(caipin){
    		$("#store_id").val("{$caipin.store_id}");
    		$("#type_id").val("{$caipin.type_id}");
    	}
    layui.use('upload', function(){
      var upload = layui.upload;
      //执行实例
      var uploadInst = upload.render({
        elem: '#thumb' //绑定元素
        ,url: "{:url('common/upload')}" //上传接口
        ,done: function(res){
          //上传完毕回调
          if(res.code == 2) {
            $('#demo1').attr('src',res.src);
            $('#upload-thumb').append('<input type="hidden" name="thumb" value="'+ res.src +'">');
          } else {
            layer.msg(res.msg);
          }
        }
        ,error: function(){
          //请求异常回调
          //演示失败状态，并实现重传
          var demoText = $('#demoText');
          demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
          demoText.find('.demo-reload').on('click', function(){
            uploadInst.upload();
          });
        }
      });
    });
    </script>
    <script>
        var message;
        layui.config({
            base: '__JS__/',
            version: '1.0.1'
        }).use(['app', 'message'], function() {
            var app = layui.app,
                $ = layui.jquery,
                layer = layui.layer;
            //将message设置为全局以便子页面调用
            message = layui.message;
            //主入口
            app.set({
                type: 'iframe'
            }).init();
        });
        
        
      layui.use(['layer', 'form'], function() {
          var layer = layui.layer,
              $ = layui.jquery,
              form = layui.form;
          $(window).on('load', function() {
              form.on('submit(admin)', function(data) {
                  $.ajax({
                      url:"{:url('admin/dinner/add_caipin')}",
                      data:$('#admin').serialize(),
                      type:'post',
                      async: false,
                      success:function(res) {
                          if(res.code ==200) {
                              var index=parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
														  window.parent.location.reload();//刷新父页面
														   parent.layer.close(index);//关闭弹出层
                          } else {
                              layer.msg(res.msg);
                          }
                      }
                  })
                  return false;
              });
          });
      });
      
      var index = '';
      function overShow(){  
      //配置一个透明的询问框
	      index = layer.msg('温馨提示<br>您输入的数值越大，优惠越大<br>例：商品原价￥100.00<br>优惠比例输入20%<br>则实际收款为￥80.00元<br> 算法：￥100.00-(100.00*20%)=￥80.00', {
	        time:  '', //20s后自动关闭
	        btnAlign: 'c'//按钮居中 
	      }); 
      }
      
      function outHide(){
      	layer.close(index);
      }
    </script>
  </div>
</body>
</html>